package com.wjb.xietong.ota.tab1;

import java.util.Calendar;

import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

import com.wjb.xietong.R;
import com.wjb.xietong.control.WJBControl;
import com.wjb.xietong.datamanager.LoginUserDataManager;
import com.wjb.xietong.ota.BaseOTA;
import com.wjb.xietong.server.IRequestResultListener;
import com.wjb.xietong.server.topic.ReplyParam;
import com.wjb.xietong.server.topic.TopicResponse.TopicInfo;
import com.wjb.xietong.util.EnumDefine.Login_User_Info;

public class OTAComment extends BaseOTA {

	private long topicInfoID;
	
	private EditText etComment;
	private Button btnSubmit;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		topicInfoID = getIntent().getLongExtra("action_comment", 0);

		setContentField(getLayoutInflater()
				.inflate(R.layout.page_comment, null));
		setTopBarAndAction(getString(R.string.STR_WORK_CIRCLE_03),
				new OnClickListener() {

					@Override
					public void onClick(View arg0) {
						app_.getActManager().popActivity();
					}
				}, null);
	}


	@Override
	protected void findView(View v) {
		etComment = (EditText) v.findViewById(R.id.message);
		btnSubmit = (Button) v.findViewById(R.id.btn_submit_comment);
		super.findView(v);
	}

	@Override
	protected void setOnClickEvent() {
		btnSubmit.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				requestCommentById(topicInfoID, etComment.getText().toString());
			}
		});
		super.setOnClickEvent();
	}

	private void requestCommentById(long infoID, String content){
		long uniqueID = Calendar.getInstance().getTimeInMillis();
		IRequestResultListener listener = new IRequestResultListener() {

			@Override
			public void requestSuccess(long requestUniqueID) {
				System.out.println("cdy test: success");
				app_.getActManager().popActivity();
			}

			@Override
			public void requestFaield(long requestUniqueID,
					String errCode, String errMsg) {
				System.out.println("cdy test: failed");
			}
		};
		//发表评论
		ReplyParam param4 = new ReplyParam();
		param4.setCompanyId((Long) LoginUserDataManager.getLoginUserInfo(Login_User_Info.COM_ID));
		param4.setTopicId(infoID);
		param4.setUserId((Long) LoginUserDataManager.getLoginUserInfo(Login_User_Info.ID));
		param4.setContent(content);
		WJBControl.requestReply(uniqueID, param4, listener);
	}
}
